import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'assetsOrderM',
  state: {},
  effects: {
    *queryAssetsInfo({ payload, callback }, { call, put }) {
      const res = yield call(api.qualificationManagement.queryOne, payload);
      if (res && res.success == true) {
        callback('success', res.data);
      } else {
        callback('fail');
        message.error(`${res?.message}`);
      }
    },
    //簿记下达
    *tradeBookSave({ payload, callback }, { call, put }) {
      const response = yield call(api.assetsOrder.tradeBookSave, payload);

      if (response && response.code == 0) {
        callback('success');
        message.success('簿记下达成功');
      } else {
        callback();
        message.error(response ? response.message || '簿记下达失败' : '簿记下达失败');
      }
    },
    //指令下达
    *orderSave({ payload, callback }, { call, put }) {
      const response = yield call(api.assetsOrder.orderSave, payload);
      if (response && response.code == 0) {
        callback('success');
        message.success('指令下达成功');
      } else {
        callback();
        message.error(response ? response.msg || '指令下达失败' : '指令下达失败');
      }
    },

    reducers: {
      save(state, { payload }) {
        return {
          ...state,
          ...payload,
        };
      },
    },
  },
};
